<?php
/**
 * Author: Traveler
 * Time  : 2021/8/31 17:00
 */

namespace app\model;


use sunshine\basic\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;
use think\model\relation\HasOne;

class IcafeModel extends BaseModel
{
    /**
     * 模型名称
     *
     * @var string
     */
    protected $name = 'icafe';

    /**
     * 搜索器：id
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchIdAttr($query, $value, $data)
    {
        $query->where('id', $value);
    }

    /**
     * 搜索器：name
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchNameAttr($query, $value, $data)
    {
        $query->whereLike('name', '%' . $value . '%');
    }

    /**
     * 搜索器：category
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchCategoryAttr($query, $value, $data)
    {
        $query->where('category_id', $value);
    }

    /**
     * 搜索器：contact
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchContactAttr($query, $value, $data)
    {
        $query->whereLike('contact', '%' . $value . '%');
    }

    /**
     * 搜索器：cellphone
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchCellphoneAttr($query, $value, $data)
    {
        $query->whereLike('cellphone', '%' . $value . '%');
    }

    /**
     * 搜索器：status
     *
     * @param $query
     * @param $value
     * @param $data
     */
    public function searchStatusAttr($query, $value, $data)
    {
        $query->where('status', $value);
    }

    /**
     * 模型关联：category
     *
     * @return BelongsTo
     */
    public function category(): BelongsTo
    {
        return $this->belongsTo(IcafeCategoryModel::class, 'category_id');
    }

    /**
     * 模型关联：wan
     *
     * @return HasMany
     */
    public function wan(): HasMany
    {
        return $this->HasMany(IcafeWanModel::class, 'icafe_id');
    }

    /**
     * 模型关联：adsl
     *
     * @return HasMany
     */
    public function adsl(): HasMany
    {
        return $this->HasMany(IcafeAdslModel::class, 'icafe_id');
    }

    /**
     * 模型关联：mirror
     *
     * @return HasOne
     */
    public function mirror(): HasOne
    {
        return $this->hasOne(IcafeMirrorModel::class, 'icafe_id');
    }

    /**
     * 模型关联：cnk
     *
     * @return HasOne
     */
    public function cnk(): HasOne
    {
        return $this->hasOne(IcafeCnkModel::class, 'icafe_id');
    }
}